#include "Player.h"

using namespace YoghurtGum;

Player::Player() : Entity()
{
	m_Sprite = Root::GetSingleton().GetRenderer()->CreateSprite("ship");
	m_Fire = 0;
}

Player::Player( float a_X, float a_Y ) : Entity(a_X, a_Y)
{
	m_Sprite = Root::GetSingleton().GetRenderer()->CreateSprite("ship");
	m_X = a_X;
	m_Y = a_Y;
	m_Fire = 0;
}

void Player::Restart(int a_Width, int a_Height)
{
	m_X = (float)(a_Width / 2) - 16.f;
	m_Y = (float)(a_Height - 32);

	Log::GetSingleton().Print("Position: (%f, %f)", m_X, m_Y);
}

void Player::Update()
{
	if (Keyboard::Get().Pressed(YGK_LEFT)) { m_X--; }
	if (Keyboard::Get().Pressed(YGK_RIGHT)) { m_X++; }
	m_Sprite->Draw((float)m_X, (float)m_Y);

	m_Fire++;
	if (m_Fire >= 25 && Keyboard::Get().Pressed(YGK_UP))
	{
		m_Fire = 0;	

		Entity* bullet = new Bullet(m_X + 10, m_Y);
		bullet->SetDepth(-100.f);
		Scene::Get()->AddObject(bullet);
	}
}